package com.health.db.service.user.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.health.db.dao.order.IDateStuffScheduleDao;
import com.health.db.dao.user.IStuffListDao;
import com.health.db.model.DateStuffSchedule;
import com.health.db.model.DateStuffScheduleExample;
import com.health.db.model.StuffList;
import com.health.db.service.user.IStuffListService;
import com.health.mapp.bean.QueryRegisterDoctorListResp;


@Component("stuffListService")
public class StuffListServiceImpl implements IStuffListService {
	
	@Autowired
	private IStuffListDao stuffListDao;
	
	@Autowired
	private IDateStuffScheduleDao dateStuffScheduleDao;

	@Override
	public List<StuffList> selectByDepartmentId(Integer departmentId) {
		// TODO Auto-generated method stub
		return stuffListDao.selectByDepartmentId(departmentId);
	}

	@Override
	public StuffList selectByStuffId(Long stuffId) {
		// TODO Auto-generated method stub
		return stuffListDao.selectByStuffId(stuffId);
	}
	
	@Override
	public List<DateStuffSchedule> selectByExample(DateStuffScheduleExample example) {
		// TODO Auto-generated method stub
		return dateStuffScheduleDao.selectByExample(example);
	}
	
	
	@Override
	public 	 QueryRegisterDoctorListResp selectDateStuffSchedule(String date,Integer departmentId) {
		// TODO Auto-generated method stub
		
		//返回参数
		QueryRegisterDoctorListResp bean = new QueryRegisterDoctorListResp();
		
		List<StuffList> stuffList = selectByDepartmentId(departmentId);
		
		
		//专家医生
		 List<StuffList> expertDoctorList = new ArrayList<StuffList>();;
		
		//普通医生
		 List<StuffList> generalDoctorList =  new ArrayList<StuffList>();; 
		
		List<StuffList> stuffListnew = new ArrayList<StuffList>();
		
		DateStuffScheduleExample example = new DateStuffScheduleExample();
		
		example.setScheduleDate(date);
		
		List<DateStuffSchedule> DateStuffScheduleList = selectByExample(example);
		
		Set<Long>  stuffSet= new HashSet<>();
		
		//查询医生排班信息
		for (int i = 0; i < DateStuffScheduleList.size(); i++) {
			
			DateStuffSchedule dateStuffSchedule = DateStuffScheduleList.get(i);
			String[] stuffIds = dateStuffSchedule.getStuffIdSolts().split(",");
			for (int j = 0; j < stuffIds.length; j++) {
				stuffSet.add(Long.valueOf(stuffIds[j]));
			}
		}
		
		//查询医生科室信息
		for (int i = 0; i < stuffList.size(); i++) {
			
			StuffList  stuff = stuffList.get(i);
			
			if (stuffSet.contains(stuff.getStuffId())) {
				
				stuffListnew.add(stuff);
				//专家医生
				if (null!=stuff.getRoleid()&&stuff.getRoleid().intValue()==1) {
					expertDoctorList.add(stuff);
				//普通医生
				}else{
					generalDoctorList.add(stuff);
				}
			
			}
		}
		
		
		bean.setDoctorList(stuffListnew);
		bean.setExpertDoctorList(expertDoctorList);
		bean.setGeneralDoctorList(generalDoctorList);
		
		return bean;
	}

	public IStuffListDao getStuffListDao() {
		return stuffListDao;
	}

	public void setStuffListDao(IStuffListDao stuffListDao) {
		this.stuffListDao = stuffListDao;
	}

	public IDateStuffScheduleDao getDateStuffScheduleDao() {
		return dateStuffScheduleDao;
	}

	public void setDateStuffScheduleDao(IDateStuffScheduleDao dateStuffScheduleDao) {
		this.dateStuffScheduleDao = dateStuffScheduleDao;
	}
	
	public static void main(String[] args) {
		Set<Long>  set= new HashSet<>();
		
		set.add(Long.valueOf(1250000));
		set.add(Long.valueOf(256));
		
		System.out.println(set.contains(Long.valueOf(1250000)));
		
		
	}
	
}
